package com.sinoglobal.ningxia.thread;

import android.os.AsyncTask;

import com.sinoglobal.ningxia.R;
import com.sinoglobal.ningxia.frame.ITask;

/**
 * @author qiwx
 * @createdate 2014-6-17 上午10:32:40
 * @Description:
 */
public abstract class ItktOtherAsyncTask<Params, Progress, Result> extends AsyncTask<Params, Progress, Result> implements
		ITask<Params, Progress, Result> {

	private String message;
	private boolean cancelable = true;
	private boolean isShowProgressDialog = true;

	public ItktOtherAsyncTask() {
	}

	public ItktOtherAsyncTask(String message) {
		this.message = message;
	}

	public ItktOtherAsyncTask(boolean isShowProgressDialog) {
		this.isShowProgressDialog = isShowProgressDialog;
	}

	/**
	 * 是否显示进度对话框
	 * 
	 * @param isShowProgressDialog
	 *            false不显示请求网络提示框，true：显示请求网络提示框
	 * @param message
	 *            显示的信息
	 */
	public ItktOtherAsyncTask(boolean isShowProgressDialog, String message) {
		this.isShowProgressDialog = isShowProgressDialog;
		this.message = message;
	}

	/**
	 * 加载进度条提示语
	 * 
	 * @param message
	 *            显示的信息
	 * @param cancelable
	 *            是否支付取消操作, 建议此值为true,
	 */
	public ItktOtherAsyncTask(String message, boolean cancelable) {
		this.message = message;
		this.cancelable = cancelable;
	}

	@Override
	protected void onPreExecute() {
		if (isShowProgressDialog) {
			
		}
		super.onPreExecute();
	}

	@Override
	protected Result doInBackground(Params... params) {
		try {
			return before(params);
		} catch (Exception e) {
			e.printStackTrace();
			
			cancel(false);
		}
		return null;
	}

	@Override
	protected void onPostExecute(Result result) {
		super.onPostExecute(result);
		if (isShowProgressDialog) {
		
		}
		after(result);

	}

	@Override
	protected void onCancelled() {
		super.onCancelled();
		if (isShowProgressDialog) {
		}
	}
}
